<?php
require_once(dirname(__FILE__) . '/config/index.php');

class TestOfHash extends UnitTestCase {

	protected $hsh;

	public function setUp() {
		$this->hsh = new Nina_Hash(array('apple' => 1, 'carrot' => 3, 'banana' => 2));
	}

	public function testGet() {
		$this->assertEqual($this->hsh->get(), array('apple' => 1, 'carrot' => 3, 'banana' => 2));
	}
	
	public function testLength() {
		$this->assertEqual($this->hsh->length(), 3);
	}
	
	public function testContains() {
		$this->assertTrue($this->hsh->contains('apple'));
		$this->assertFalse($this->hsh->contains('date'));
	}
	
	public function testSearch() {
		$this->assertEqual($this->hsh->search(1), 'apple');
		$this->assertFalse($this->hsh->search(4));
	}

	public function testInsert() {
		$this->hsh->insert('date', 4);
		$this->assertTrue($this->hsh->contains('date'));
		$this->assertEqual($this->hsh->search(4), 'date');		
	}

	public function testRemove() {
		$this->hsh->remove('carrot');
		$this->assertFalse($this->hsh->contains('carrot'));
		$this->assertFalse($this->hsh->search(3));
	}

	public function testSort() {
		$this->assertEqual($this->hsh->sort(), array('apple' => 1, 'banana' => 2, 'carrot' => 3));
		$this->assertEqual($this->hsh->sort(false), array('carrot' => 3, 'banana' => 2, 'apple' => 1));
	}

	public function testMerge() {
		$hsh = $this->hsh->merge(array('date' => 4, 'egg'  => '5'));
		$this->assertEqual($this->hsh->get(), array('apple' => 1, 'carrot' => 3, 'banana' => 2, 'date' => 4, 'egg'  => 5));
	}

	public function testDiff() {
		$this->assertEqual($this->hsh->diff(array('apple' => 1, 'carrot' => 3)), array('banana' => 2));
	}
}
